package com.webserve.core;

import com.webserve.http.EmptyRequestException;
import com.webserve.http.HttpServletRequest;
import com.webserve.http.HttpServletResponse;

import javax.xml.stream.events.StartDocument;
import java.io.IOException;
import java.net.Socket;

public class ClientHandler implements Runnable{
    Socket socket;

    public ClientHandler(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        //第一步
        try {
            HttpServletRequest request = new HttpServletRequest(socket);
            HttpServletResponse response = new HttpServletResponse(socket);

            //第二步
             DispatcherServlet.getServlet().start(request,response);

            //第三步
            response.start();
        } catch (IOException | EmptyRequestException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }




}
